//
//  TJTaskManagerDetailHeaderView.m
//  BaoDian
//
//  Created by mac on 2024/8/3.
//

#import "TJTaskManagerDetailHeaderView.h"
#import "TJUserPublishDataView.h"

@interface TJTaskManagerDetailHeaderView()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *subTitleLabel;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) TJUserPublishDataView *dataView;
@property (nonatomic, weak) UILabel *beginDateLabel;
@property (nonatomic, weak) UILabel *endDateLabel;
@property (nonatomic, weak) UILabel *stateValueLabel;
@property (nonatomic, weak) UILabel *timeFrameValueLabel;
@property (nonatomic, weak) UILabel *videoCountValueLabel;
@property (nonatomic, weak) UILabel *dateValueLabel;

@end

@implementation TJTaskManagerDetailHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        UILabel *titleLabel = [UILabel lableWithSuperView:self font:UIFontBoldMake(22) color:UIColor.whiteColor title:@"任务进行中..." textAlignment:NSTextAlignmentLeft];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(10);
            make.left.offset(0);
        }];
        
        UILabel *subTitleLabel = [UILabel lableWithSuperView:self font:UIFontMake(12) color:UIColor.whiteColor title:@"The mission is underway..." textAlignment:NSTextAlignmentLeft];
        subTitleLabel.alpha = 0.8;
        [subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(8);
            make.left.equalTo(titleLabel);
            make.right.inset(leftRightMargin);
        }];
        
        UIView *taskView = [UIView addToView:self];
        taskView.backgroundColor = UIColorMake(0x1E1F23);
        taskView.addCornerRadius(12);
        [taskView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.inset(0);
            make.bottom.inset(24);
            make.top.equalTo(subTitleLabel.mas_bottom).offset(22);
        }];
        
        UIView *topView = [UIView addToView:taskView];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.inset(0);
            make.top.offset(0);
            make.height.offset(48);
        }];
        
        UIImageView *iconImageView = [UIImageView addToView:topView];
        iconImageView.image = [UIImage imageNamed:@"groupIcon"];
        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(20);
            make.centerY.offset(0);
            make.left.offset(16);
        }];
        
        UILabel *nameLabel = [UILabel lableWithSuperView:topView font:UIFontMake(16) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentCenter];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.left.equalTo(iconImageView.mas_right).offset(6);
        }];
        
        TJUserPublishDataView *dataView = [TJUserPublishDataView addToView:taskView];
        dataView.backgroundColor = UIColorMake(0x2A2B31);
        dataView.addCornerRadius(8);
        dataView.publishCountItem.textLabel.text = @"_";
        dataView.playerCountItem.textLabel.text = @"_";
        dataView.likeCountItem.textLabel.text = @"_";
        dataView.commentCountItem.textLabel.text = @"_";
        [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.inset(16);
            make.height.offset(52);
            make.top.equalTo(topView.mas_bottom);
        }];
        
        UILabel *beginDateView = [UILabel lableWithSuperView:taskView font:UIFontMake(11) color:UIColor.whiteColor title:@"始" textAlignment:NSTextAlignmentCenter];
        beginDateView.addCornerRadius(4);
        beginDateView.backgroundColor = UIColorMake(0x2978F0);
        [beginDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(dataView.mas_bottom).offset(14);
            make.left.inset(16);
            make.width.height.offset(16);
        }];
        
        UILabel *beginDateLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"开始时间：--" textAlignment:NSTextAlignmentLeft];
        [beginDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(beginDateView);
            make.left.equalTo(beginDateView.mas_right).inset(16);
        }];
        
        UILabel *endDateView = [UILabel lableWithSuperView:taskView font:UIFontMake(11) color:UIColor.whiteColor title:@"终" textAlignment:NSTextAlignmentCenter];
        endDateView.addCornerRadius(4);
        endDateView.backgroundColor = UIColorMake(0xFFAC3F);
        [endDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(beginDateView.mas_bottom).offset(14);
            make.left.inset(16);
            make.width.height.offset(16);
        }];
        
        UILabel *endDateLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"结束时间：--" textAlignment:NSTextAlignmentLeft];
        [endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(endDateView);
            make.left.equalTo(endDateView.mas_right).inset(16);
        }];
        
        UIView *lineView = [UIView addToView:topView];
        lineView.backgroundColor = UIColorMake(0x2A2B31);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.inset(16);
            make.height.offset(1);
            make.top.equalTo(endDateView.mas_bottom).offset(12);
        }];
        
        UILabel *stateLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"持续发布" textAlignment:NSTextAlignmentLeft];
        [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView.mas_bottom).offset(14);
            make.left.inset(16);
        }];
        
        UILabel *stateValueLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"持续发布2个月" textAlignment:NSTextAlignmentCenter];
        [stateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(stateLabel);
            make.right.inset(16);
        }];
        
        UILabel *dateLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"发布时间" textAlignment:NSTextAlignmentLeft];
        [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(stateLabel.mas_bottom).offset(10);
            make.left.equalTo(iconImageView);
        }];
        
        UILabel *dateValueLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
        [dateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(dateLabel);
            make.right.equalTo(lineView);
        }];
        
        UILabel *timeFrameLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"发布时段" textAlignment:NSTextAlignmentLeft];
        [timeFrameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(dateLabel.mas_bottom).offset(10);
            make.left.equalTo(dateLabel);
        }];
        
        UILabel *timeFrameValueLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
        [timeFrameValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(timeFrameLabel);
            make.right.equalTo(lineView);
        }];
        
        UILabel *videoCountLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"发布视频数" textAlignment:NSTextAlignmentLeft];
        [videoCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(timeFrameLabel.mas_bottom).offset(10);
            make.left.equalTo(dateLabel);
        }];
        
        UILabel *videoCountValueLabel = [UILabel lableWithSuperView:taskView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
        [videoCountValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(videoCountLabel);
            make.right.equalTo(lineView);
        }];
 
        _titleLabel = titleLabel;
        _subTitleLabel = subTitleLabel;
        _nameLabel = nameLabel;
        _dataView = dataView;
        _beginDateLabel = beginDateLabel;
        _endDateLabel = endDateLabel;
        _stateValueLabel = stateValueLabel;
        _timeFrameValueLabel = timeFrameValueLabel;
        _videoCountValueLabel = videoCountValueLabel;
        _dateValueLabel = dateValueLabel;
     }
    return self;
}

- (void)setModel:(TJTaskManageModel *)model {
    _model = model;
    
    _nameLabel.text = model.taskName;
    
    _beginDateLabel.text = [NSString stringWithFormat:@"开始时间：%@", model.startDate ?: @"--"];
    _endDateLabel.text = [NSString stringWithFormat:@"结束时间：%@", model.endDate ?: @"--"];
    _stateValueLabel.text = [NSString stringWithFormat:@"%@月", model.continuedNumber];
    _timeFrameValueLabel.text = model.taskDate;
    _dateValueLabel.text = model.createDate;
    _videoCountValueLabel.text = [NSString stringWithFormat:@"%@个", model.number];
    _dataView.publishCountItem.textLabel.text = model.sendCount;
    _dataView.playerCountItem.textLabel.text = model.playCount;
    _dataView.likeCountItem.textLabel.text = model.diggCount;
    _dataView.commentCountItem.textLabel.text = model.commentCount;
    
    if (model.taskStatus.intValue == 3) {
        _titleLabel.text = @"任务进行中...";
        _subTitleLabel.text = @"The mission is underway...";
    } else if (model.taskStatus.intValue == 5 || model.taskStatus.intValue == 4) {
        _titleLabel.text = @"任务已结束...";
        _subTitleLabel.text = @"The mission is over...";
    }  else {
        _titleLabel.text = @"任务未启动...";
        _subTitleLabel.text = @"The mission not started...";
    }
    
}

@end
